﻿using System;
using DevExpress.XtraEditors;

namespace WinForm.Modules
{
    public partial class GridControlBase : XtraUserControl
    {
        public DevExpress.XtraGrid.GridControl GridControl
        {
            get { return gridControl1; }
        }

        public GridControlBase()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 设置GridView的样式
        /// </summary>
        private void InitGridViewAppearence()
        {
            //ID 列不显示
            if (gridView1.Columns["Id"] != null)
            {
                gridView1.Columns["Id"].Visible = false;
            }
            
            //所有列不能获得焦点
            foreach (DevExpress.XtraGrid.Columns.GridColumn column in gridView1.Columns)
            {
                column.OptionsColumn.AllowFocus = false;
            }
        }

        /// <summary>
        /// 显示行号
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
        {
            if (e.Info.IsRowIndicator && e.RowHandle >= 0)
            {
                e.Info.DisplayText = (e.RowHandle + 1).ToString();
            }
        }

        private void gridControl1_DataSourceChanged(object sender, EventArgs e)
        {
            InitGridViewAppearence();
        }
    }
}
